﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class BM_GoPay : System.Web.UI.Page
{
    HuatICBCPayService.ICBCService payService = new HuatICBCPayService.ICBCService();
    HuatICBCPayService.ICBC payICBCModel = new HuatICBCPayService.ICBC();

    protected void Page_Load(object sender, EventArgs e)
    {
        payService.CookieContainer = new System.Net.CookieContainer();
        if (payService.Verify("cet.huat.edu.cn", "8260147"))
        {
            string orderId = Request.QueryString[0].ToString();
            DataTable dt = Exam.getOrderInfoByOrderID(orderId);
            if (dt.Rows.Count > 0)
            {
                DataRow dr = dt.Rows[0];
                DataTable dtTime = Exam.getEmTimeByEmId(dr["EmID"].ToString());
                NoAccess.JumpToDefaultPageNoAccessTime(this, dr["EmID"].ToString());
                string emYear = string.Empty;

                DataRow drTime = dtTime.Rows[0];

                //string payorderid = "OrderID-" + dr["OrderID"].ToString() + "-" + dr["ExamYear"].ToString() + "-" + dr["ExamNumber"].ToString() + "-" + dr["TypeID"].ToString();
                string payOrderId = "CET" + drTime["EmYear"].ToString() + drTime["EmNum"].ToString() +"-" + dr["OrderID"].ToString();
                DataTable dtPayOrder = payService.GetOrderInfo(orderId);
                if (dtPayOrder.Rows.Count > 0)
                {
                    if (dtPayOrder.Rows[0]["transtat"].ToString() == "1")
                    {
                        Response.Redirect(BSUtility.mainUrl + "Users/PayReturn.aspx?OrderID=" + payOrderId);
                    }
                }

                payICBCModel = payService.signData(payOrderId, dr["StudIdcard"].ToString(), "BMJF", dr["EmAllName"].ToString() + Session["userName"].ToString(), dr["EMCost"].ToString());
                this.Controls.Add(new LiteralControl(payService.PostOrderForm(payICBCModel)));
            }
            else
            {
                //BSUtility.WindowAlert(Page, "订单信息读取失败，请重新点击支付");
            }
        }
    }
}